<?php
class NamhochockiesController extends AppController {

	var $name = 'Namhochockies';

	function index() {
		$this->Namhochocky->recursive = 0;
		$this->set('namhochockies', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid namhochocky', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('namhochocky', $this->Namhochocky->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Namhochocky->create();
			if ($this->Namhochocky->save($this->data)) {
				$this->Session->setFlash(__('The namhochocky has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The namhochocky could not be saved. Please, try again.', true));
			}
		}
		$namhocs = $this->Namhochocky->Namhoc->find('list');
		$hockies = $this->Namhochocky->Hocky->find('list');
		$this->set(compact('namhocs', 'hockies'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid namhochocky', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Namhochocky->save($this->data)) {
				$this->Session->setFlash(__('The namhochocky has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The namhochocky could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Namhochocky->read(null, $id);
		}
		$namhocs = $this->Namhochocky->Namhoc->find('list');
		$hockies = $this->Namhochocky->Hocky->find('list');
		$this->set(compact('namhocs', 'hockies'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for namhochocky', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Namhochocky->delete($id)) {
			$this->Session->setFlash(__('Namhochocky deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Namhochocky was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
